import TsconfigPathsPlugin from 'tsconfig-paths-webpack-plugin';

const {
  TARO_APP_PROJECT,
  TARO_APP_NAME,
} = process.env;

const config = {
  projectName: TARO_APP_PROJECT,
  date: '2023-11-28',
  designWidth: 375,
  deviceRatio: {
    640: 2.34 / 2,
    750: 1,
    375: 2,
    828: 1.81 / 2,
  },
  sourceRoot: 'src',
  outputRoot: 'dist',
  plugins: [
    '@tarojs/plugin-html',
  ],
  defineConstants: {},
  copy: {
    patterns: [],
    options: {},
  },
  framework: 'react',
  compiler: {
    type: 'webpack5',
    prebundle: {
      enable: !1,
    },
  },
  cache: {
    enable: !1, // Webpack 持久化缓存配置，建议开启。默认配置请参考：https://docs.taro.zone/docs/config-detail#cache
  },
  mini: {
    postcss: {
      pxtransform: {
        enable: !0,
        config: {
          selectorBlackList: ['nut-'],
        },
      },
      url: {
        enable: !0,
        config: {
          limit: 1024, // 设定转换尺寸上限
        },
      },
      cssModules: {
        enable: !1, // 默认为 false，如需使用 css modules 功能，则设为 true
        config: {
          namingPattern: 'module', // 转换模式，取值为 global/module
          generateScopedName: '[name]__[local]___[hash:base64:5]',
        },
      },
    },
    webpackChain(chain) {
      chain.resolve.plugin('tsconfig-paths')
        .use(TsconfigPathsPlugin);
    },
  },
  h5: {
    publicPath: '/',
    staticDirectory: 'static',
    output: {
      filename: 'js/[name].[hash:8].js',
      chunkFilename: 'js/[name].[chunkhash:8].js',
    },
    miniCssExtractPluginOption: {
      ignoreOrder: !0,
      filename: 'css/[name].[hash].css',
      chunkFilename: 'css/[name].[chunkhash].css',
    },
    postcss: {
      pxtransform: {
        enable: !0,
        config: {
          selectorBlackList: ['nut-'],
        },
      },
      autoprefixer: {
        enable: !0,
        config: {},
      },
      cssModules: {
        enable: !1, // 默认为 false，如需使用 css modules 功能，则设为 true
        config: {
          namingPattern: 'module', // 转换模式，取值为 global/module
          generateScopedName: '[name]__[local]___[hash:base64:5]',
        },
      },
    },
    webpackChain(chain) {
      chain.resolve.plugin('tsconfig-paths')
        .use(TsconfigPathsPlugin);
    },
  },
  rn: {
    appName: TARO_APP_NAME,
    postcss: {
      cssModules: {
        enable: !1, // 默认为 false，如需使用 css modules 功能，则设为 true
      },
    },
  },
};

export default config;
